<script type="text/javascript" src="__JS__/uploadify/jquery.uploadify.min.js"></script>
<div class="wechat-add-img">
  <input type="file" id="upload_picture">
  <div class="upload-img-box">
    <notempty name="param.images">
      <volist name="param.images" id="vo">
        <div class="upload-pre-item" id="item_{$vo['id']}">
          <input type="hidden" name="{$param.name}" value="{$vo['id']}" class="icon" />
          <img src="__ROOT__{$vo['path']}" data-id="{$vo['id']}"/>
          <span class='btn-close' title='删除图片'></span>
        </div>
      </volist>
    </notempty>
  </div>
</div>
  
<!-- <div class="wechat-add-item">
  <a href="javascript:;">选择商品</a>
</div> -->

<script type="text/javascript">
  //上传图片
  /* 初始化上传插件 */
  $('#upload_picture').uploadify({
    'height': 36,
    'swf': '__JS__/uploadify/uploadify.swf?ver=' + Math.random(),
    'fileObjName': 'download',
    'buttonText': '上传图片',
    'uploader': "{:U('File/uploadPicture', array('session_id'=>session_id()))}",
    'width': 80,
    'removeTimeout': 1,
    'fileTypeExts': '*.jpg; *.png; *.gif;',
    'onUploadSuccess': uploadPicture,
    'uploadLimit': 1,
    'onFallback':function(){
      alert('未检测到兼容版本的Flash');
    }
  });

  function uploadPicture(file, data){
    var data = eval("(" + data + ")");
    //var data = $.parseJSON(data);
    var src = '';
    if(data.status){
      //创建<div class="upload-pre-item">
      var upload_item = $("<div class='upload-pre-item' id='item_"+data.id+"'></div>");
      //创建img input close-btn
      var img_path = $("<input type='hidden' name='{$param.name}' class='icon' value='"+data.id+"'/>");
      src = data.url || '__ROOT__' + data.path;
      var upload_img = $("<img src=" + src +" title='点击显示大图' data-id="+data.id+">");
      var img_del = $("<span class='btn-close' title='删除图片'></span>");

      //加入到upload-img-box
      upload_item.append(upload_img);
      upload_item.append(img_del);
      upload_item.append(img_path);
      $('.upload-img-box').append(upload_item);

      /*加入微信预览*/
      $('.J_attach_view').attr('src', src);
    }else{
      updateAlert(data.info);
      setTimeout(function(){
        $('#top-alert').find('button').click();
        $(that).removeClass('disabled').prop('disabled', false);
      },1500);
    }
  }
</script>